﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using TRPOP.Common;
using TRPOP.CMS.Web.UI;


using TRPOP.CMS.Business;
using TRPOP.CMS.Model;
using Newtonsoft.Json;
using System.Text.RegularExpressions;
using TRPOP.Config;

namespace TRPOP.CMS.Web.Admin
{
    public partial class Node_Save : BaseAdmin
    {

        #region 当前页面权限验证
        protected override void SubPageInit()
        {
            base.m_SubPagePermission = Plugin.PermissionKeys.PermissionEnum.Node_Save;
        }
        #endregion

        #region 页面变量
        protected bool m_IsAdd = true;
        /// <summary>
        /// 父节点ID
        /// </summary>
        protected int m_pid = 0;
        /// <summary>
        /// 结点ID
        /// </summary>
        protected int m_id = 0;
        protected string m_strParentName = string.Empty;
        protected string m_strNodeName = string.Empty;
        protected NodeInfo m_NodeInfo = new NodeInfo();
        protected NodeManage m_NodeManage = new NodeManage();
        protected string m_strAction = string.Empty;
        /// <summary>
        /// 移动结点所属的父节点
        /// </summary>
        protected int m_intNewPid = 0;
        /// <summary>
        /// 基于对象结点的ID
        /// </summary>
        protected int m_intBaseId = 0;
        protected string strOptions = string.Empty;
        /// <summary>
        /// 模板的基本路径
        /// </summary>
        protected string strBaseTemplate = SYSConfig.SystemVar_Templatepath;
        #endregion

        #region 页面事件

        protected void Page_Load(object sender, EventArgs e)
        {
            //页面传递参数处理
            m_strAction = RequestHelper.RequestString("ac");
            m_id = RequestHelper.RequestInt("nodeid");
            m_pid = RequestHelper.RequestInt("pid");
            m_intNewPid = RequestHelper.RequestInt("newpid", -1);
            m_intBaseId = RequestHelper.RequestInt("baseid");
            //验证用户对结点的权限
            if (m_id > 0)
                base.AlertForNoPermission(base.CheckIsHavePermission(m_id));
            else
            {
                base.AlertForNoPermissionAddNode(m_NodeManage.IsOverFlow());
            }
            LoadTree();
            if (!IsPostBack)
            {
                LoadBase();
                BindData();
            }
        }
        /// <summary>
        /// 结点类型的选择响应事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ddlNodeTypeId_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlNodeTypeId.SelectedValue == ((int)NodeType.EnumElement.TrueNode).ToString())//如果实结点
            {
                tr_ddlInheritNodeID.Visible = false;
                tr_ddlModelId.Visible = true;
            }
            else if (ddlNodeTypeId.SelectedValue == ((int)NodeType.EnumElement.VirualNode).ToString())//如果虚结点
            {
                tr_ddlInheritNodeID.Visible = true;
                tr_ddlModelId.Visible = false;
            }
        }
        /// <summary>
        /// 确定点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            bool blNodeTypeChange = false;//是否改变了结点类型
            bool blnPSNChange = false;//是否改变了静态发布点
            bool blnPSNSource = false;//是否改变了资源发布点
            string strPSNSourceold = string.Empty;//原来的资源发布点
            if (m_id > 0)//如果是修改结点信息
            {
                #region 修改信息时所做的数据操作
                if (GetPageViewState("NodeInfo") != null)
                {
                    m_NodeInfo = (NodeInfo)GetPageViewState("NodeInfo");
                }
                else
                {
                    m_NodeInfo = m_NodeManage.GetInfoById(m_id);
                }
                if (m_NodeInfo == null)
                {
                    //m_NodeInfo = new NodeInfo(); 之前的代码，其实要这段代码没用
                    base.Redirect("../error.aspx?msg=您所操作的结点不存在");
                    return;
                }
                else
                {
                    m_NodeInfo.UpdateTime = DateTime.Now;
                    m_NodeInfo.UpdateUserId = base.mUserBaseInfo.UserBaseId;
                }
                #endregion
                base.SaveLog(Plugin.LogKeys.OperObject.NodeOper, Plugin.LogKeys.OperResult.EditSubmit);
            }
            else
            {
                #region 新增结点所做的基本赋值操作
                //如果m_NodeInfo为空，创建一个NodeInfo
                if (m_NodeInfo == null)
                    m_NodeInfo = new NodeInfo();
                m_NodeInfo.ParentId = m_pid;
                m_NodeInfo.AddTime = DateTime.Now;
                m_NodeInfo.AddUserId = base.mUserBaseInfo.UserBaseId;
                m_NodeInfo.UpdateTime = DateTime.Now;
                m_NodeInfo.UpdateUserId = base.mUserBaseInfo.UserBaseId;
                m_NodeInfo.NodeTypeId = ddlNodeTypeId.SelectedValue.ToInt();
                if (m_NodeInfo.NodeTypeId == (int)NodeType.EnumElement.VirualNode)
                {
                    m_NodeInfo.InheritNodeID = RequestHelper.RequestInt("ddlInheritNodeID");
                    NodeInfo InheritNodeInfo = m_NodeManage.GetInfoById(m_NodeInfo.InheritNodeID);
                    if (InheritNodeInfo != null && InheritNodeInfo.NodeTypeId == (int)NodeType.EnumElement.TrueNode)
                    {
                        m_NodeInfo.ModelId = InheritNodeInfo.ModelId;
                    }
                    else
                    {
                        Alert("虚结点只能继承实结点");
                        return;
                    }
                }
                else
                {
                    m_NodeInfo.ModelId = ddlModelId.SelectedValue.ToInt();
                }
                #endregion
                base.SaveLog(Plugin.LogKeys.OperObject.NodeOper, Plugin.LogKeys.OperResult.AddSubmit);
            }
            //结点关键字
            m_NodeInfo.KeyWord = txtKeyWord.Text.RemoveHtml();
            //是否改变了结点类型
            blNodeTypeChange = (m_NodeInfo.NodeId > 0 && m_NodeInfo.ContentPubTypeId != rbtnContentPubTypeId.SelectedValue.ToInt());
            //内容页模板
            m_NodeInfo.DetailTemplate = ("/" + txtDetailTemplateRoot.Value + "/" + txtDetailTemplate.TextFilterSQL).Replace("//", "/");
            //内容页命名规则
            m_NodeInfo.HtmlNameReg = txtHtmlNameReg.TextFilterSQL;
            //是否改变了静态发布点
            blnPSNChange = (m_NodeInfo.NodeId > 0 && m_NodeInfo.HtmlPSN != txtHtmlPSN.TextFilterSQL);
            //是否改变了资源发布点
            blnPSNSource = (m_NodeInfo.NodeId > 0 && m_NodeInfo.SourcePSN != txtSourcePSN.TextFilterSQL);
            //老的资源发布点
            strPSNSourceold = m_NodeInfo.SourcePSN;
            //静态内容发布点  
            if (!txtHtmlPSN.TextFilterSQL.IsEmpty())
            {
                //copy 一份 list.aspx动态页到目的psn点 这个是之前的处理
                string sourcePath = string.Empty, targetPath = string.Empty;
                Match oMatch = CommonRegex.MatchHttpUrl(SYSConfig.SystemVar_NodeIndexPage);
                if (oMatch.Success)
                    sourcePath = Common.Util.GetMapPath(oMatch.Groups["root"].Value);
                else
                    sourcePath = Common.Util.GetMapPath(SYSConfig.SystemVar_NodeIndexPage);
                targetPath = Common.Util.GetMapPath((new PSNManage()).GetPSNPathByPSN(txtHtmlPSN.TextFilterSQL));
                string fileName = sourcePath.Substring(sourcePath.LastIndexOf("\\") + 1, sourcePath.Length - sourcePath.LastIndexOf("\\") - 1);
                FileUtil.CopyFile(sourcePath, targetPath + "\\" + fileName, true);
                //赋值静态资源发布点
                m_NodeInfo.HtmlPSN = txtHtmlPSN.TextFilterSQL;
            }
            // 静态内容页目录规则
            m_NodeInfo.HtmlRootReg = txtHtmlRootReg.TextFilterSQL;
            //  静态内容页发布URL
            m_NodeInfo.HtmlUrl = txtHtmlUrl.Text;
            // 首页模板
            m_NodeInfo.IndexTemplate = ("/" + txtIndexTemplateRoot.Value + "/" + txtIndexTemplate.TextFilterSQL).Replace("//", "/");
            //结点名称
            m_NodeInfo.Name = txtName.Text;
            //资源发布的相关赋值
            m_NodeInfo.SourcePSN = txtSourcePSN.Text;
            m_NodeInfo.SourceRootReg = txtSourceRootReg.Text;
            m_NodeInfo.SourceUrl = txtSourceUrl.Text;
            // 发布模式
            m_NodeInfo.ContentPubTypeId = rbtnContentPubTypeId.SelectedValue.ToInt();
            //是否自动发布
            m_NodeInfo.IsAuoPub = rblIsAuoPub.SelectedValue == "1" ? true : false;
            //内容编辑器
            m_NodeInfo.Editor = ddlEditor.SelectedValue;
            //内容分页生成器
            m_NodeInfo.Pager = ddlPager.SelectedValue;
            //结点首页文件名
            m_NodeInfo.IndexName = txtIndexName.Text;
            //结点水印
            m_NodeInfo.WaterPic = TxtWaterpic.Text.Trim();
            //动态发布下的结点页面设置
            m_NodeInfo.IndexPortalURL = txtIndexPortalURL.Text;
            m_NodeInfo.ContentPortalURL = txtContentPortalURL.Text;
            //SEO关键字
            m_NodeInfo.SEODescription = txtSEODescription.TextTrim;
            m_NodeInfo.SEOKey = txtSEOKey.TextTrim;
            m_NodeInfo.SEOTitle = txtSEOTitle.TextTrim;

            #region 必填项判断,并更新了URL
            //静态发布状态下的逻辑判断
            if (m_NodeInfo.ContentPubTypeId == (int)ContentPubType.EnumElement.StaticPub)
            {
                #region 静态发布状态下的逻辑判断 同时设置了Node的URL
                if (base.CheckIfEmptyAndAlert("请设置发布点", m_NodeInfo.HtmlPSN))
                    return;
                if (base.CheckIfEmptyAndAlert("请设置发布点URL", m_NodeInfo.HtmlUrl))
                    return;
                if (base.CheckIfEmptyAndAlert("请设置结点首页文件名", m_NodeInfo.IndexName))
                    return;
                //设置Node的URL

                m_NodeInfo.Url = (new PSNManage()).GetPSNURLByPSNUrl(m_NodeInfo.HtmlUrl, m_NodeInfo.IndexName);

                if (base.CheckIfEmptyAndAlert("请设置首页模板", m_NodeInfo.IndexTemplate))
                    return;
                if (base.CheckIfEmptyAndAlert("请设置内容页模板", m_NodeInfo.DetailTemplate))
                    return;
                if (base.CheckIfEmptyAndAlert("请设置资源发布URL", m_NodeInfo.SourceUrl))
                    return;
                if (base.CheckIfEmptyAndAlert("请设置资源发布点", m_NodeInfo.SourcePSN))
                    return;
                if (base.CheckIfEmptyAndAlert("内容页面名命规则不能为空", m_NodeInfo.HtmlNameReg))
                    return;
                if (!CommonRegex.MatchExtFile(m_NodeInfo.HtmlNameReg).Success)
                {
                    Alert("请填写正确的内容页面名命规则后缀");
                    return;
                }
                #endregion
            }
            else if (m_NodeInfo.ContentPubTypeId == (int)ContentPubType.EnumElement.DynamicPub)
            {
                #region 动态发布状态下的逻辑判断
                if (base.CheckIfEmptyAndAlert("请设置首页模板", m_NodeInfo.IndexTemplate))
                    return;
                if (base.CheckIfEmptyAndAlert("请设置内容页模板", m_NodeInfo.DetailTemplate))
                    return;
                if (base.CheckIfEmptyAndAlert("请设置结点首页入口URL", m_NodeInfo.IndexPortalURL))
                    return;
                if (base.CheckIfEmptyAndAlert("请设置内容入口URL", m_NodeInfo.ContentPortalURL))
                    return;
                if (base.CheckIfEmptyAndAlert("请设置资源发布点和资源发布URL", m_NodeInfo.SourcePSN, m_NodeInfo.SourceUrl))
                    return;
                if (m_NodeInfo.NodeId == 0)
                {
                    m_NodeManage.Save(m_NodeInfo);
                    m_NodeInfo.Url = m_NodeManage.PageName(m_NodeInfo.IndexPortalURL, 0, m_NodeInfo.NodeId, 0, 1, m_NodeInfo.AddTime);
                }
                else
                {
                    m_NodeInfo.Url = m_NodeManage.PageName(m_NodeInfo.IndexPortalURL, 0, m_NodeInfo.NodeId, 0, 1, m_NodeInfo.AddTime);
                }
                #endregion
            }
            #endregion

            /*  进行保存及相关的级联更新操作  */
            bool blnIsAdd = m_NodeInfo.NodeId <= 0;
            //结点类型改变 或 静态发布点改变
            if (blNodeTypeChange || blnPSNChange)
            {
                m_NodeManage.Save(m_NodeInfo);
                tipmsg.InnerHtml = "因为发布模式或PSN修改";
                panel_main.Visible = false;
                panel_reset.Visible = true;
            }
            else
            {
                SubmitAlert(m_NodeManage.Save(m_NodeInfo));
                //lcheng 增加模板选择
                using (TRPOP.CMS.Plugin.PluginAssistForTemplate oPluginAssist = new Plugin.PluginAssistForTemplate())
                {
                    oPluginAssist.NodeTemplateSaveEvent += RecomManage.NodeTemplateSave;
                    oPluginAssist.SavePluginTemplate(m_NodeInfo.NodeId);
                }
            }
            //如果资源发布点改变了，就更新相关的图片库的信息
            if (blnPSNSource)
            {
                m_NodeManage.ResetAllPSN(m_NodeInfo, strPSNSourceold);
            }
            //如果新增结点，则刷新tree，反之则不更新
            if (blnIsAdd)
            {
                ExecuteJs("top.frames[\"leftwin\"].window.location.reload(true);top.mainwin_Open('../publish/admin_publish_list.aspx?nodeid=" + m_NodeInfo.NodeId + "');");
            }
            else
            {
                ExecuteJs("top.mainwin_Open('../publish/admin_publish_list.aspx?nodeid=" + m_NodeInfo.NodeId + "');");
            }
        }

        #endregion

        #region 页面方法
        /// <summary>
        ///  第一次加载页面时加载的数据: ParentNodeInfo 、 NodeInfo 、 基本的控件绑定
        /// </summary>
        public void LoadBase()
        {
            //获取父节点信息，并绑定页面上的变量值
            if (m_pid > 0 && m_id == 0)
            {
                NodeInfo m_ParentNodeInfo = m_NodeManage.GetInfoById(m_pid);
                if (m_ParentNodeInfo != null)
                {
                    m_strParentName = getNodeParentName(m_ParentNodeInfo.Name, m_ParentNodeInfo.ParentId);
                }
            }
            //lcheng 增加模板选择, 通过插件的形式增加额外的模板选择
            using (TRPOP.CMS.Plugin.PluginAssistForTemplate oPluginAssist = new Plugin.PluginAssistForTemplate())
            {
                oPluginAssist.NodeTemplateShowEvent += RecomManage.NodeTemplateShow;
                oPluginAssist.InitPluginTemplate(ltTemplate, m_id);
            }
            //内容模型的绑定
            ddlModelId.DataSource = (new ModelManage()).GetListByCondition(0, "", " ModelId asc");
            ddlModelId.DataBind();
            //结点类型的绑定
            ddlNodeTypeId.DataSource = (new NodeTypeManage()).GetListByCondition(0, "", " NodeTypeId asc");
            ddlNodeTypeId.DataBind();
            ddlNodeTypeId.SelectedIndex = 0;
            //发布模式的绑定
            rbtnContentPubTypeId.DataSource = (new ContentPubTypeManage()).GetListByCondition(0, "", " ContentPubTypeId asc");
            rbtnContentPubTypeId.DataBind();
            rbtnContentPubTypeId.SelectedIndex = 0;
            //原来的稿件工作流代码
            //ddlContentWorkFlowId.DataSource = (new ContentWorkFlowManage()).GetListByCondition(0, "", " ContentWorkFlowId asc");
            //ddlContentWorkFlowId.DataBind();
            //资源发布目录规则
            ddlSourceRootReg.DataSource = PageAssist.SourceRootReg;
            ddlSourceRootReg.DataBind();
            //静态页面生成规则
            ddlHtmlRootReg.DataSource = PageAssist.SourceRootReg;
            ddlHtmlRootReg.DataBind();
            //编辑器绑定
            ddlEditor.DataSource = SYSConfig.ContentEditors;
            ddlEditor.DataBind();
            //内容分页生成器
            ddlPager.DataSource = SYSConfig.ContentPagers;
            ddlPager.DataBind();
        }
        /// <summary>
        /// 绑定所有的结点,用于创建虚节点时继承
        /// </summary>
        private void LoadTree()
        {
            List<NodeInfoWithLevel> m_NodeListTree = (new NodeManage()).GetNodeListTree(0, 0, "");
            if (m_NodeListTree == null)
                m_NodeListTree = new List<NodeInfoWithLevel>();
            foreach (NodeInfoWithLevel info in m_NodeListTree)
            {
                if (info.NodeId == m_pid)
                {
                    strOptions += "<option value=\"" + info.NodeId + "\" selected=\"selected\">" + PageAssist.AppendStr(info.Level, ("&nbsp;&nbsp;&nbsp;&nbsp;")) + " -" + info.Name + "</option>";
                }
                else
                {
                    strOptions += "<option value=\"" + info.NodeId + "\">" + PageAssist.AppendStr(info.Level, ("&nbsp;&nbsp;&nbsp;&nbsp;")) + " -" + info.Name + "</option>";
                }
            }
        }
        /// <summary>
        /// 结点信息的绑定
        /// </summary>
        public void BindData()
        {

            if (m_id > 0)//如果传递的结点id大于0，那么就根据具体的该结点信息绑定结点的基本信息
            {
                #region 如果不是新增结点，则是修改结点信息（包含移动结点的操作）
                m_IsAdd = false;//添加、修改信息的标示
                //如果根据结点信息不存在，并且结点隐藏 , 则直接跳出本页面
                if ((m_NodeInfo = m_NodeManage.GetInfoById(m_id)) == null || m_NodeInfo.IsHidde)
                {
                    m_NodeInfo = new NodeInfo();
                    base.Redirect("../error.aspx?msg=您所查找的结点不存在");
                    return;
                }
                //如果移动结点
                if (m_intNewPid >= 0)
                {
                    m_NodeManage.MoveNodeToNewParentId(m_id, m_intNewPid);
                    ExecuteJsWidthEnd("alert('移动成功');window.location.href='Node_save.aspx?nodeid=" + m_id + "';");
                }
                //将nodeinfo保存在试图里
                InitPageViewState("NodeInfo", m_NodeInfo);
                //父节点名称
                m_strParentName = getNodeParentName(m_NodeInfo.Name, m_NodeInfo.ParentId);
                //当前结点名称
                m_strNodeName = m_NodeInfo.Name;
                // 结点的内容页模板 模板相对路径
                if (!m_NodeInfo.DetailTemplate.IsEmpty() && m_NodeInfo.DetailTemplate.StartsWith(strBaseTemplate))
                {
                    txtDetailTemplate.Text = m_NodeInfo.DetailTemplate.Substring(strBaseTemplate.Length);
                }
                else
                    txtDetailTemplate.Text = m_NodeInfo.DetailTemplate;
                // 结点的内容页模板 模板根路径
                txtDetailTemplateRoot.Value = strBaseTemplate;
                //内容页命名规则
                txtHtmlNameReg.Text = m_NodeInfo.HtmlNameReg;
                //静态发布PSN
                txtHtmlPSN.Text = m_NodeInfo.HtmlPSN;
                //内容页目录命名规则
                txtHtmlRootReg.Text = m_NodeInfo.HtmlRootReg;
                ddlHtmlRootReg.SelectedValue = m_NodeInfo.HtmlRootReg;
                //静态内容发布URL 
                txtHtmlUrl.Text = m_NodeInfo.HtmlUrl;
                // 结点的首页页模板 模板相对路径
                if (!m_NodeInfo.IndexTemplate.IsEmpty() && m_NodeInfo.IndexTemplate.StartsWith(strBaseTemplate))
                {
                    txtIndexTemplate.Text = m_NodeInfo.IndexTemplate.Substring(strBaseTemplate.Length);
                }
                else
                    txtIndexTemplate.Text = m_NodeInfo.IndexTemplate;
                // 结点的首页页模板 模板根路径
                txtIndexTemplateRoot.Value = strBaseTemplate;
                // 结点唯一标示符
                txtKeyWord.Text = m_NodeInfo.KeyWord;
                txtKeyWord.Enabled = false;
                //结点名称
                txtName.Text = m_NodeInfo.Name;
                //资源发布点
                txtSourcePSN.Text = m_NodeInfo.SourcePSN;
                //资源发布目录规则   
                txtSourceRootReg.Text = m_NodeInfo.SourceRootReg;
                ddlSourceRootReg.SelectedValue = m_NodeInfo.SourceRootReg;
                //资源发布URL
                txtSourceUrl.Text = m_NodeInfo.SourceUrl;
                //发布模式
                rbtnContentPubTypeId.SelectedValue = m_NodeInfo.ContentPubTypeId.ToString();
                //内容模型
                ddlModelId.SelectedValue = m_NodeInfo.ModelId.ToString();
                ddlModelId.Enabled = false;
                tr_ddlModelId.Visible = true;
                //结点类型
                ddlNodeTypeId.SelectedValue = m_NodeInfo.NodeTypeId.ToString();
                ddlNodeTypeId.Enabled = false;
                rblIsAuoPub.SelectedValue = m_NodeInfo.IsAuoPub ? "1" : "0";
                //内容编辑器
                ddlEditor.SelectedValue = m_NodeInfo.Editor;
                //分页生成器
                ddlPager.SelectedValue = m_NodeInfo.Pager;
                //结点首页文件名
                txtIndexName.Text = m_NodeInfo.IndexName;
                //动态发布的 结点首页
                txtIndexPortalURL.Text = m_NodeInfo.IndexPortalURL;
                //动态发布的 内容页首页
                txtContentPortalURL.Text = m_NodeInfo.ContentPortalURL;
                //结点水印
                TxtWaterpic.Text = m_NodeInfo.WaterPic;
                //SEO
                txtSEODescription.Text = m_NodeInfo.SEODescription;
                txtSEOKey.Text = m_NodeInfo.SEOKey;
                txtSEOTitle.Text = m_NodeInfo.SEOTitle;
                #endregion
            }
            else
            {
                #region 新增结点： 基于某结点建立结点、或直接建立新结点
                //如果是基于某结点建立的结点，则将该结点拷贝一份，以此作为基础来创建
                if (m_intBaseId > 0)
                {
                    m_NodeInfo = m_NodeManage.GetInfoById(m_intBaseId);
                }
                else//创建新的结点
                {
                    m_NodeInfo = new NodeInfo();
                    txtSourceRootReg.Text = ddlSourceRootReg.SelectedValue;
                    txtHtmlRootReg.Text = ddlHtmlRootReg.SelectedValue;
                    m_NodeInfo.IndexPortalURL = SYSConfig.SystemVar_listAutoPage; //CMSConfig.CMSURL + "/publish/index.apsx?nodeid={NodeID}&page={Page}";
                    m_NodeInfo.ContentPortalURL = SYSConfig.SystemVar_ContentAutoPage; //CMSConfig.CMSURL + "/publish/content.aspx?id={IndexID}&page={Page}";
                }
                //结点名称
                m_strNodeName = m_NodeInfo.Name;
                //内容页命名规则
                txtHtmlNameReg.Text = m_NodeInfo.HtmlNameReg;
                //静态发布PSN
                txtHtmlPSN.Text = m_NodeInfo.HtmlPSN;
                //内容发布目录规则
                txtHtmlRootReg.Text = m_NodeInfo.HtmlRootReg;
                //内容页发布URL
                txtHtmlUrl.Text = m_NodeInfo.HtmlUrl;
                //首页模板
                if (!m_NodeInfo.IndexTemplate.IsEmpty() && m_NodeInfo.IndexTemplate.StartsWith(strBaseTemplate))
                {
                    txtIndexTemplate.Text = m_NodeInfo.IndexTemplate.Substring(strBaseTemplate.Length);
                }
                else
                    txtIndexTemplate.Text = m_NodeInfo.IndexTemplate;
                txtIndexTemplateRoot.Value = strBaseTemplate;
                //内容页模板
                if (!m_NodeInfo.DetailTemplate.IsEmpty() && m_NodeInfo.DetailTemplate.StartsWith(strBaseTemplate))
                {
                    txtDetailTemplate.Text = m_NodeInfo.DetailTemplate.Substring(strBaseTemplate.Length);
                }
                else
                    txtDetailTemplate.Text = m_NodeInfo.DetailTemplate;
                txtDetailTemplateRoot.Value = strBaseTemplate;
                // 资源发布点
                txtSourcePSN.Text = m_NodeInfo.SourcePSN;
                // 资源发布目录规则
                txtSourceRootReg.Text = m_NodeInfo.SourceRootReg;
                // 资源发布URL
                txtSourceUrl.Text = m_NodeInfo.SourceUrl;
                //发布模式
                rbtnContentPubTypeId.SelectedValue = m_NodeInfo.ContentPubTypeId.ToString();
                // 内容模型
                ddlModelId.SelectedValue = m_NodeInfo.ModelId.ToString();
                //结点首页文件名
                txtIndexName.Text = m_NodeInfo.IndexName;
                //动态发布的 首页
                txtIndexPortalURL.Text = m_NodeInfo.IndexPortalURL;
                //动态发布的 内容页
                txtContentPortalURL.Text = m_NodeInfo.ContentPortalURL;
                //结点类型默认选择1
                ddlNodeTypeId.SelectedValue = "1";
                tr_ddlNodeTypeId.Visible = true;
                //内容模型显示出来
                tr_ddlModelId.Visible = true;
                //结点信息添加标识
                m_IsAdd = true;
                #endregion
            }
        }
        /// <summary>
        /// 获取父节点名称
        /// </summary>
        /// <param name="name"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        private string getNodeParentName(string name, int id)
        {
            if (id <= 0)
                return name;
            NodeInfo m_ParentNodeInfo = m_NodeManage.GetInfoById(id);
            if (m_ParentNodeInfo != null)
            {
                name = m_ParentNodeInfo.Name + (name.IsEmpty() ? "" : ("&nbsp;-&gt;&nbsp;" + name));
                if (m_ParentNodeInfo.ParentId > 0)
                {
                    name = getNodeParentName(name, m_ParentNodeInfo.ParentId);
                }
            }
            return name;
        }

        #endregion

    }
}
